import axios from 'axios';
export default {
  install(Vue) {
    Vue.prototype.httpGet = function (url, success) {
      axios({
          method: "get",
          url: url
        })
        .then(res => {
          if(res.data.code == 602){
            alert("登陆过期，请重新登陆");
            this.$router.push("/");
          }else{
            success(res.data);
          } 
        })
        .catch(function (error) {
          console.log(error);
        });
    };
    //POST
    Vue.prototype.httpPost = function (url, data, success) {
      axios({
          method: "post",
          data: data,
          url: url
        })
        .then(res => {
          if(res.data.code == 602){
            alert("登陆过期，请重新登陆");
            this.$router.push("/");
          }else{
            success(res.data);
          } 
        })
        .catch(function (error) {
          console.log(error);
        });
    };
    //PUT
    Vue.prototype.httpPut = function (url, data, success) {
      axios({
          method: "put",
          data: data,
          url: url
        })
        .then(res => {
          if(res.data.code == 602){
            alert("登陆过期，请重新登陆");
            this.$router.push("/");
          }else{
            success(res.data);
          } 
        })
        .catch(function (error) {
          console.log(error);
        });
    };

  }

}
